*RCRA Nationwide Hedonic Study
*Extrapolation Excercise
*Created: 6/1/2021
*Created by: Dennis Guignet
*Last Revised: 5/25/2023
*Last Revised by: Dennis Guignet

********************************************************************************
 
*This do-file takes the hedonic results and first calculates the total 
*	capitalization effects across all "impacted" parcels. It then estimates  
*	a variant of the hedonic regressions suggested by Banzhaf (2021) to derive 
*	an ex post lower bound welfare estimate. Ultimately, the code here generates
*	the estimates presented in Figure 6 and Table 4 in the main text. 


********************************************************************************
********************************************************************************


*set empty cells for factor variables to drop
set emptycells drop
clear all
*increase max variables allowed b/c factor variables
set maxvar 100000

*set directory for results
cd "$resultsfolder"

*set key parameters for capitalization and welfare calculations
global pbarpost 206950 
	*Note: This is the mean transaction price in 2018, based on 627 post-CA sales
	*	within 0-750m (see a few lines below).  
global Nparcels 25415 
	*Note: Number of post-CA parcels, see details a few lines below after bring
	*	in parcel dataset. 
global Nmidparcels 41973
	*Note: This is number of parcels within 0-750m of an open CA site, as of the 
	*	end of our study period (2018). 
	
********************************************************************************
********************************************************************************

*bring in sales dataset to get nationwide post-CA price for homes within 750 meters.
use "$salesfolder\All_Sales_Final_Cleaned_CA1500m", replace	
sum rprice if dpostCA0_750==1 & tranyr==2018, detail
	*Note: Mean price is $206,950. This is value set for global variable above. 
	
tab tranyr if dpostCA0_750==1
	*Note: At least have highest number of sales (n=627) in last year, which 
	*	is most relevant for ex post welfare calculations later. 
	
********************************************************************************
********************************************************************************	
	
*Rerun model 2 in from Table 3 in main paper, but just with mid and post  
*	observations (i.e., all pre-CA sales within 0-750m or 750-1500 are dropped). 
*	The resulting estimates are labelled as Model 5 in Table 4 of final paper. 
use "$salesfolder\All_Sales_Final_Cleaned_CA5k", replace

*code up global variable for TSD counts	
local vars  cntTSD
foreach v of local vars {
	global `v' `v'0_250 `v'250_500 `v'500_750 `v'750_1000 ///
		`v'1000_1250 `v'1250_1500 `v'1500_1750 `v'1750_2000 ///
		`v'2000_2250 `v'2250_2500 `v'2500_2750 `v'2750_3000 ///
		`v'3000_3250 `v'3250_3500 `v'3500_3750 `v'3750_4000 ///
		`v'4000_4250 `v'4250_4500 `v'4500_4750 `v'4750_5000 
	}

*Need to re-set CA global variables for this sample
local stages /*pre*/ mid post 
foreach s of local stages {
	global d`s'CA d`s'CA0_750 d`s'CA750_1500 /*d`s'CA1500_5000*/
	}	

count	
drop if dpreCA0_750>0 | dpreCA750_1500>0
count
	*Note: Sample size went from 2,538,334 to 2,522,076, dropping 16,268 sales. 
	
reghdfe lnrprice $cntTSD $dmidCA $dpostCA, ///
	absorb(i.mycntyid#i.tranyr i.mycntyid#i.quarter i.mytractid ///
	i.mycntyid#i.tranyr#c.($house)) vce(cluster mycntyid)  compact poolsize(20)
eststo m4_nopre
estimates save "$raw_resultsfolder\m4_nopre", replace	


*bring in parcel level dataset
use "$salesfolder\All_parcel_CA_counts_750m.dta", clear
tab cntpostCA0_750	
	*Note: 25,415 post-CA single-family residential parcels within 750-meters. 
tab cntmidCA0_750
count if cntmidCA0_750>0
	*Note: 41,973 mid-CA single-family residential parcels within 750-meters.

	
*Restore results from Model 5 in the main paper. 
estimates use "$raw_resultsfolder/m4_nopre"
	*Note: Selected for comparability with welfare excercise later, which
	*	uses variant of Model 2 b/c need full 5k sample of CA to identify numerous
	*	interaction terms, and because it is conservative in the sense that it is 
	*	lowest among most credible estimates.

*Estimate corresponding capitalization effects for completed cleanups. These are 
*	estimates for Model 5 in Table 4 of final paper.
eststo Ests5: nlcom ///
	(D3PostMid_0_750: ((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)) ///
	(MeanDeltaP_PostMid_0_750: $pbarpost*(((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)) ///
			/(1+(exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)))) ///
	(TotalDeltaP_0_750m: $Nparcels*($pbarpost*(((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)) ///
			/(1+(exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1))))),  post	
			
*Estimate corresponding capitalization effects if open cleanups completed. 
estimates use "$raw_resultsfolder/m4_nopre"
eststo Ests5mid_to_post: nlcom ///
	(D3PostMid_0_750: ((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)) ///
	(MeanDeltaP_PostMid_0_750: $pbarpost*(((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)) ///
			/(1+(exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)))) ///
	(TotalDeltaP_0_750m: $Nmidparcels*($pbarpost*(((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)) ///
			/(1+(exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1))))),  post	
	
*Export capitalization estimates 	
esttab Ests5 using "$resultsfolder\CapitalizationEffects_Model5.csv", replace label csv compress ///
	nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) /*se(4)*/ ci(4) scalars(ll)


********************************************************************************
********************************************************************************	

*Estimate lowerbound of ex post welfare effects of cleanup based on variation of
*	Banzhaf (2021) framework.  Based on variants of Model 5 in main paper. Estimates
*	below correspond to Model 5' and 5'' in Table 4 of final paper. 


*Bring in data and set up global variables
use "$salesfolder\All_Sales_Final_Cleaned_CA5k", clear

count	
drop if dpreCA0_750>0 | dpreCA750_1500>0
count
	*Note: Sample size went from 2,538,334 to 2,522,076, dropping 16,268 sales. 

*Create Region variable based on states
gen region=""
replace region="Northeast" if State=="CT"|State=="ME"|State=="MA"|State=="NH"| ///
	State=="RI"|State=="VT"|State=="NJ"|State=="NY"|State=="PA"
replace region="Midwest" if State=="IN"|State=="IL"|State=="MI"|State=="OH"| ///
	State=="WI"|State=="IA"|State=="CT"|State=="KS"|State=="MN"|State=="MO"| ///
	State=="NE"|State=="ND"|State=="SD"
replace region="South" if State=="DE"|State=="DC"|State=="FL"|State=="GA"| ///
	State=="MD"|State=="NC"|State=="SC"|State=="VA"|State=="WV"|State=="AL"| ///
	State=="KY"|State=="MS"|State=="TN"|State=="AR"|State=="LA"|State=="OK"| ///
	State=="TX"
replace region="West" if State=="AZ"|State=="CO"|State=="ID"|State=="NM"| ///
	State=="MT"|State=="UT"|State=="NV"|State=="WY"|State=="AK"|State=="CA"| ///
	State=="HI"|State=="OR"|State=="WA"
count 
tab region	
tab region dpostCA0_750

*generate interactions with relevant CA variables
gen R1=(region=="Northeast")
gen R2=(region=="Midwest")
gen R3=(region=="South")
gen R4=(region=="West")
	
*house and location attributes global var
global house lnacres lnacres_miss stories stories_miss bathtot bathtot_miss lnsqft ///
	lnsqft_miss age agesq age_miss p_nbdev_2011_200 p_nbdev_2011_500 hwy500m
	
*code up global variable for TSD counts	
local vars  cntTSD
foreach v of local vars {
	global `v' `v'0_250 `v'250_500 `v'500_750 `v'750_1000 ///
		`v'1000_1250 `v'1250_1500 `v'1500_1750 `v'1750_2000 ///
		`v'2000_2250 `v'2250_2500 `v'2500_2750 `v'2750_3000 ///
		`v'3000_3250 `v'3250_3500 `v'3500_3750 `v'3750_4000 ///
		`v'4000_4250 `v'4250_4500 `v'4500_4750 `v'4750_5000 
	}

*Loop through to create interaction terms between stage dummies and year of sale
local stages /*pre*/ mid post 
foreach s of local stages {
	forvalues y=2000/2017 {
		gen d`s'CA0_750_y`y'=0
		replace d`s'CA0_750_y`y'=d`s'CA0_750 if tranyr==`y'
		gen d`s'CA750_1500_y`y'=0
		replace d`s'CA750_1500_y`y'=d`s'CA750_1500 if tranyr==`y'
		}
	global d`s'CA_Yrs d`s'CA0_750_y* d`s'CA750_1500_y*     
	}
	*Note: Changed inner loop to just go to 2017, instead of 2018. 
	*	Therefore, 2018 will be omitted category. 


********************************************************************************

*Model 5' in Table 4 and Figure 6 of final paper. 

*set base global variables for omitted 2018 category
local stages /*pre*/ mid post 
foreach s of local stages {
	global d`s'CA d`s'CA0_750 d`s'CA750_1500
	}	

reghdfe lnrprice /*$dpreCA $dpreCA_Yrs*/ $dmidCA $dmidCA_Yrs $dpostCA $dpostCA_Yrs, ///
	absorb(i.mycntyid#i.tranyr i.mycntyid#i.quarter i.mytractid ///
	i.mycntyid#i.tranyr#c.($house) i.tranyr#c.($cntTSD) ///
	i.R1#c.($cntTSD) i.R2#c.($cntTSD) i.R3#c.($cntTSD) i.R4#c.($cntTSD)) ///
	vce(cluster mycntyid)  compact poolsize(20)
eststo m5v2 /*v2 is for variant 2 of model 5*/
estimates save "$raw_resultsfolder\m5v2", replace	

*Wald test of incremental difference relative to omitted 2018 coef jointly 
*	significant or not. 
	*Note: Essentially this tells us if deviation from flat line significant across 
	*	years, and if not significant, then can pool coefficients across years.
estimates restore m5v2 	
test (_b[dpostCA0_750_y2000]=_b[dpostCA0_750_y2001]=_b[dpostCA0_750_y2002] ///
	=_b[dpostCA0_750_y2003]=_b[dpostCA0_750_y2004]=_b[dpostCA0_750_y2005] ///
	=_b[dpostCA0_750_y2006]=_b[dpostCA0_750_y2007]=_b[dpostCA0_750_y2008] ///
	=_b[dpostCA0_750_y2009]=_b[dpostCA0_750_y2010]=_b[dpostCA0_750_y2011] ///
	=_b[dpostCA0_750_y2012]=_b[dpostCA0_750_y2013]=_b[dpostCA0_750_y2014] ///
	=_b[dpostCA0_750_y2015]=_b[dpostCA0_750_y2016]=_b[dpostCA0_750_y2017]=0) ///
	(_b[dmidCA0_750_y2000]=_b[dmidCA0_750_y2001]=_b[dmidCA0_750_y2002] ///
	=_b[dmidCA0_750_y2003]=_b[dmidCA0_750_y2004]=_b[dmidCA0_750_y2005] ///
	=_b[dmidCA0_750_y2006]=_b[dmidCA0_750_y2007]=_b[dmidCA0_750_y2008] ///
	=_b[dmidCA0_750_y2009]=_b[dmidCA0_750_y2010]=_b[dmidCA0_750_y2011] ///
	=_b[dmidCA0_750_y2012]=_b[dmidCA0_750_y2013]=_b[dmidCA0_750_y2014] ///
	=_b[dmidCA0_750_y2015]=_b[dmidCA0_750_y2016]=_b[dmidCA0_750_y2017]=0) ///
	(_b[dpostCA750_1500_y2000]=_b[dpostCA750_1500_y2001]=_b[dpostCA750_1500_y2002] ///
	=_b[dpostCA750_1500_y2003]=_b[dpostCA750_1500_y2004]=_b[dpostCA750_1500_y2005] ///
	=_b[dpostCA750_1500_y2006]=_b[dpostCA750_1500_y2007]=_b[dpostCA750_1500_y2008] ///
	=_b[dpostCA750_1500_y2009]=_b[dpostCA750_1500_y2010]=_b[dpostCA750_1500_y2011] ///
	=_b[dpostCA750_1500_y2012]=_b[dpostCA750_1500_y2013]=_b[dpostCA750_1500_y2014] ///
	=_b[dpostCA750_1500_y2015]=_b[dpostCA750_1500_y2016]=_b[dpostCA750_1500_y2017]=0) ///
	(_b[dmidCA750_1500_y2000]=_b[dmidCA750_1500_y2001]=_b[dmidCA750_1500_y2002] ///
	=_b[dmidCA750_1500_y2003]=_b[dmidCA750_1500_y2004]=_b[dmidCA750_1500_y2005] ///
	=_b[dmidCA750_1500_y2006]=_b[dmidCA750_1500_y2007]=_b[dmidCA750_1500_y2008] ///
	=_b[dmidCA750_1500_y2009]=_b[dmidCA750_1500_y2010]=_b[dmidCA750_1500_y2011] ///
	=_b[dmidCA750_1500_y2012]=_b[dmidCA750_1500_y2013]=_b[dmidCA750_1500_y2014] ///
	=_b[dmidCA750_1500_y2015]=_b[dmidCA750_1500_y2016]=_b[dmidCA750_1500_y2017]=0) 
	*Note: Reject null hypothesis that CA mid and post coefficients constant 
	*	over time (i.e., equal to omitted 2018 category) - F(72, 376)=4.85, p=0.0000
	
	
	
*Estimate Direct Unmediated Effect (DUE) along 2018 price surface. These are 
*	estimates used to populate Model 5' results in Table 4 of main text, as well
*	as Figure 6. 
*	Note: 2018 is the omitted year category, so don't need to put year interaction
*		coefficients in below calculations for 2018 (first three calculations). 
estimates restore m5v2 	
eststo TE5v2: nlcom ///
	(D3PostMid_0_750: ((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100)) ///
	(MeanDeltaP_PostMid_0_750: $pbarpost*(((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)) ///
			/(1+(exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)))) ///
	(TotalDeltaP_0_750m: $Nparcels*($pbarpost*(((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)) ///
			/(1+(exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1))))) ///
	(D3PostMid_0_750_y2017: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2017]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2017])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2017]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2017])))-1)*100)) ///
	(D3PostMid_0_750_y2016: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2016]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2016])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2016]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2016])))-1)*100)) ///
	(D3PostMid_0_750_y2015: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2015]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2015])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2015]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2015])))-1)*100)) ///
	(D3PostMid_0_750_y2014: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2014]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2014])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2014]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2014])))-1)*100)) ///		
	(D3PostMid_0_750_y2013: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2013]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2013])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2013]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2013])))-1)*100)) ///
	(D3PostMid_0_750_y2012: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2012]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2012])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2012]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2012])))-1)*100)) ///
	(D3PostMid_0_750_y2011: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2011]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2011])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2011]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2011])))-1)*100)) ///		
	(D3PostMid_0_750_y2010: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2010]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2010])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2010]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2010])))-1)*100)) ///		
	(D3PostMid_0_750_y2009: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2009]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2009])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2009]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2009])))-1)*100)) ///		
	(D3PostMid_0_750_y2008: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2008]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2008])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2008]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2008])))-1)*100)) ///		
	(D3PostMid_0_750_y2007: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2007]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2007])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2007]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2007])))-1)*100)) ///	
	(D3PostMid_0_750_y2006: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2006]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2006])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2006]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2006])))-1)*100)) ///	
	(D3PostMid_0_750_y2005: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2005]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2005])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2005]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2005])))-1)*100)) ///			
	(D3PostMid_0_750_y2004: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2004]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2004])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2004]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2004])))-1)*100)) ///	
	(D3PostMid_0_750_y2003: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2003]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2003])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2003]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2003])))-1)*100)) ///			
	(D3PostMid_0_750_y2002: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2002]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2002])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2002]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2002])))-1)*100)) ///			
	(D3PostMid_0_750_y2001: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2001]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2001])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2001]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2001])))-1)*100)) ///	
	(D3PostMid_0_750_y2000: ((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2000]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2000])) ///
		-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2000]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2000])))-1)*100)),  post	

		
*Redo total welfare calculation, but with 2017 as assumed ex post year
estimates restore m5v2 	
nlcom $Nparcels*$pbarpost*((exp(((_b[dpostCA0_750]+_b[dpostCA0_750_y2017])-(_b[dmidCA0_750]+_b[dmidCA0_750_y2017])) ///
	-((_b[dpostCA750_1500]+_b[dpostCA750_1500_y2017])-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2017])))-1) ///
	/(1+(exp(((_b[dpostCA0_750]+_b[dpostCA0_750_y2017])-(_b[dmidCA0_750]+_b[dmidCA0_750_y2017])) ///
	-((_b[dpostCA750_1500]+_b[dpostCA750_1500_y2017])-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2017])))-1)))


*test for whether statistically different across years
estimates restore m5v2 
testnl ((exp((_b[dpostCA0_750]-_b[dmidCA0_750])-(_b[dpostCA750_1500]-_b[dmidCA750_1500]))-1)*100) ///
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2017]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2017])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2017]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2017])))-1)*100) ///
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2016]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2016])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2016]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2016])))-1)*100) ///
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2015]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2015])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2015]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2015])))-1)*100) ///
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2014]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2014])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2014]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2014])))-1)*100) ///		
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2013]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2013])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2013]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2013])))-1)*100) ///
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2012]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2012])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2012]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2012])))-1)*100) ///
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2011]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2011])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2011]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2011])))-1)*100) ///		
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2010]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2010])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2010]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2010])))-1)*100) ///		
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2009]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2009])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2009]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2009])))-1)*100) ///		
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2008]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2008])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2008]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2008])))-1)*100) ///		
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2007]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2007])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2007]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2007])))-1)*100) ///	
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2006]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2006])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2006]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2006])))-1)*100) ///	
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2005]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2005])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2005]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2005])))-1)*100) ///			
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2004]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2004])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2004]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2004])))-1)*100) ///	
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2003]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2003])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2003]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2003])))-1)*100) ///			
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2002]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2002])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2002]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2002])))-1)*100) ///			
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2001]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2001])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2001]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2001])))-1)*100) ///	
		=((exp((_b[dpostCA0_750]+_b[dpostCA0_750_y2000]-(_b[dmidCA0_750]+_b[dmidCA0_750_y2000])) ///
			-(_b[dpostCA750_1500]+_b[dpostCA750_1500_y2000]-(_b[dmidCA750_1500]+_b[dmidCA750_1500_y2000])))-1)*100)
		*Note: Reject null hypothesis that estimates statistically equal (chi2(18)=41.16, p=0.0014)

		
*Export results for table 
esttab TE5v2 using ///
	"$resultsfolder\TreatmentEffectEsts_Model5v2_forWelfareCalcs.csv", replace label ///
	csv compress nogaps nolines star ///
	(* 0.10 ** 0.05 *** 0.01) b(4) ci(4) scalars(ll)	
*Export results for all years for graph and table
esttab TE5v2 using "$resultsfolder\TreatmentEffectEsts_Model5v2_AllYears.csv", replace label ///
	csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(2) se(4) scalars(ll) 
esttab TE5v2 using TreatmentEffectEsts_Model5v2_AllYearsForGraph.csv, replace label ///
		plain csv compress nogaps nolines nostar b(4) ci(4) wide noparentheses
	

*Tabulation for graphic of number of identifying observations by year; Figure A8
*	in Appendix G.	
tab tranyr dpostCA0_750		


********************************************************************************

*Model 5'' in Table 4 and Figure 6 of final paper. 

*add trend line
gen trend=tranyr-2000
tab tranyr trend
*interact trend line with CA stage and bin dummies
local stages /*pre*/ mid post 
foreach s of local stages {
	gen d`s'CA0_750_trend = d`s'CA0_750*trend
	gen d`s'CA750_1500_trend = d`s'CA750_1500*trend
	*set global for intercepts of trend lines (i.e., just the pre, mid, and post
	*	dummies)
	global d`s'CA d`s'CA0_750 d`s'CA750_1500 /*d`s'CA1500_5000*/
	}	
	
*Regression 5'': With linear trend in CAs effects across years.
reghdfe lnrprice /*$dpreCA*/ $dmidCA $dpostCA ///
	/*dpreCA0_750_trend dpreCA750_1500_trend*/ dmidCA0_750_trend dmidCA750_1500_trend ///
	dpostCA0_750_trend dpostCA750_1500_trend, ///
	absorb(i.mycntyid#i.tranyr i.mycntyid#i.quarter i.mytractid ///
	i.mycntyid#i.tranyr#c.($house) i.tranyr#c.($cntTSD) ///
	i.R1#c.($cntTSD) i.R2#c.($cntTSD) i.R3#c.($cntTSD) i.R4#c.($cntTSD)) ///
	vce(cluster mycntyid)  compact poolsize(20)
eststo m5v3
estimates save "$raw_resultsfolder\m5v3", replace	

*test joint signifigance of relevant slope terms
estimates restore m5v3
estimates use "$raw_resultsfolder\m5v3"
/*
test dpreCA0_750_trend=dpreCA750_1500_trend=dmidCA0_750_trend=dmidCA750_1500_trend ///
	=dpostCA0_750_trend=dpostCA750_1500_trend=0 
	*Note: Trend variables jointly insignificant (F(6, 376)=1.36, p=0.2303)
*/
test /*dpreCA0_750_trend=dpreCA750_1500_trend=*/dmidCA0_750_trend=dmidCA750_1500_trend ///
	=dpostCA0_750_trend=dpostCA750_1500_trend=0 	
	*Note: Fail to reject null hypothesis that trend interactions statistically
	*	insignificant: F(4, 376)=1.11, p=0.3533. 
	
*Loop through and calculate percent change in price estimates for each year. 
*	These are estimates used to populate Model 5'' results in Figure 6.
estimates use "$raw_resultsfolder\m5v3"
reghdfe /* Just reactivates results just brought back in. */
eststo m5v3 
foreach t of num 0(1)18 {	
	estimates restore m5v3 
	eststo Ests5v3_y`t': nlcom ///
		(D3PostMid_0_750_y: ((exp(((_b[dpostCA0_750]+(_b[dpostCA0_750_trend ]*`t')) ///
			-(_b[dmidCA0_750]+(_b[dmidCA0_750_trend]*`t'))) ///
			-((_b[dpostCA750_1500]+(_b[dpostCA750_1500_trend]*`t')) ///
			-(_b[dmidCA750_1500]+(_b[dmidCA750_1500_trend]*`t'))))-1)*100)), post  
	}

*2018 welfare calculations based on trend specification. These are 
*	estimates used to populate Model 5'' results in Table 4 of main text.
estimates restore m5v3
eststo WelfareEsts_y2018: nlcom ///
	(D3PostMid_0_750: ((exp(((_b[dpostCA0_750]+(_b[dpostCA0_750_trend ]*18)) ///
		-(_b[dmidCA0_750]+(_b[dmidCA0_750_trend]*18))) ///
		-((_b[dpostCA750_1500]+(_b[dpostCA750_1500_trend]*18)) ///
		-(_b[dmidCA750_1500]+(_b[dmidCA750_1500_trend]*18))))-1)*100)) ///	
	(MeanDeltaP_PostMid_0_750: $pbarpost*((exp(((_b[dpostCA0_750]+(_b[dpostCA0_750_trend ]*18)) ///
		-(_b[dmidCA0_750]+(_b[dmidCA0_750_trend]*18))) ///
		-((_b[dpostCA750_1500]+(_b[dpostCA750_1500_trend]*18)) ///
		-(_b[dmidCA750_1500]+(_b[dmidCA750_1500_trend]*18))))-1) ///
			/(1+(exp(((_b[dpostCA0_750]+(_b[dpostCA0_750_trend ]*18)) ///
		-(_b[dmidCA0_750]+(_b[dmidCA0_750_trend]*18))) ///
		-((_b[dpostCA750_1500]+(_b[dpostCA750_1500_trend]*18)) ///
		-(_b[dmidCA750_1500]+(_b[dmidCA750_1500_trend]*18))))-1)))) ///
	(TotalDeltaP_0_750m: $Nparcels*( $pbarpost*((exp(((_b[dpostCA0_750]+(_b[dpostCA0_750_trend ]*18)) ///
		-(_b[dmidCA0_750]+(_b[dmidCA0_750_trend]*18))) ///
		-((_b[dpostCA750_1500]+(_b[dpostCA750_1500_trend]*18)) ///
		-(_b[dmidCA750_1500]+(_b[dmidCA750_1500_trend]*18))))-1) ///
			/(1+(exp(((_b[dpostCA0_750]+(_b[dpostCA0_750_trend ]*18)) ///
		-(_b[dmidCA0_750]+(_b[dmidCA0_750_trend]*18))) ///
		-((_b[dpostCA750_1500]+(_b[dpostCA750_1500_trend]*18)) ///
		-(_b[dmidCA750_1500]+(_b[dmidCA750_1500_trend]*18))))-1))))), post

*Export results for table 
esttab WelfareEsts_y2018 using ///
	"$resultsfolder\TreatmentEffectEsts_Model5v3_forWelfareCalcs.csv", replace label ///
	csv compress nogaps nolines star ///
	(* 0.10 ** 0.05 *** 0.01) b(4) ci(4) scalars(ll)	
		
*Export results for all years for graph and table
esttab Ests5v3_y0 Ests5v3_y1 Ests5v3_y2 Ests5v3_y3 Ests5v3_y4 ///
	Ests5v3_y5 Ests5v3_y6 Ests5v3_y7 Ests5v3_y8 Ests5v3_y9 ///
	Ests5v3_y10 Ests5v3_y11 Ests5v3_y12 Ests5v3_y13 Ests5v3_y14 ///
	Ests5v3_y15 Ests5v3_y16 Ests5v3_y17 Ests5v3_y18 ///
	using "$resultsfolder\TreatmentEffectEsts_Model5v3_LinearTrend.csv", ///
	replace label mtitle("2000" "2001" "2002" "2003" "2004" "2005" "2006" "2007" ///
	"2008" "2009" "2010" "2011" "2012" "2013" "2014" "2015" "2016" "2017" "2018") ///
	csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(2) se(4) scalars(ll) ///
	keep(D3PostMid_0_750_y)	
	
esttab Ests5v3_y0 Ests5v3_y1 Ests5v3_y2 Ests5v3_y3 Ests5v3_y4 ///
	Ests5v3_y5 Ests5v3_y6 Ests5v3_y7 Ests5v3_y8 Ests5v3_y9 ///
	Ests5v3_y10 Ests5v3_y11 Ests5v3_y12 Ests5v3_y13 Ests5v3_y14 ///
	Ests5v3_y15 Ests5v3_y16 Ests5v3_y17 Ests5v3_y18 ///
	using "$resultsfolder\TreatmentEffectEsts_Model5v3_LinearTrend_ForGraphs.csv", ///
	replace label plain csv compress nogaps nolines nostar b(4) ci(4) ///
	wide noparentheses keep(D3PostMid_0_750_y)	

*export hedonic regression results for appendix
esttab m4_nopre using "$resultsfolder\HedonicReg_Model5v1_NoPre_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll N_g) r2 ar2	
esttab m5v2 using "$resultsfolder\HedonicReg_Model5v2_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll N_g) r2 ar2	
esttab m5v3 using "$resultsfolder\HedonicReg_Model5v3_NoCEM.csv", replace label csv compress nogaps nolines star (* 0.10 ** 0.05 *** 0.01) b(4) se(4) scalars(ll N_g) r2 ar2	

*END




